/**
 * 类名：主页业务类
 * 备注：负责主页业务逻辑。（公告、登陆）
 * 作者：rankin
 * 日期：2016/03/4
 */
var Page = require('../models/page');
var Log = require('../models/log');

module.exports = {

    /**
     * 跳转至首页
     */
    index: function (req, res, next) {
        res.render('index', {
            sess: 0,
            layout: false
        });
    },
    main: function (req, res) {
        res.render('main');
    },
    log: function (req, res) {
        var sess = req.session.user;
        var page = new Page(req.query.num);
        var obj = {
            page: page,
            search: {}
        };
        new Log().findForPage(obj, function (err, count, pageCount, datas) {
            if (err) {
            }
            page.pageCount = pageCount;
            var dates = [];
            for (var i = 0; i < datas.length; i++) {
                dates.push((datas[i].date).toFormat('YYYY-MM-DD HH24:MI:SS'));
            }
            res.render('system/operation_log', {
                datas: datas,
                dates: dates,
                page: page
            });
        })
    },
    fault: function (req, res) {
        var sess = req.session.user;
        var page = new Page(req.query.num);
        var obj = {
            page: page,
            search: {}
        };
        new Log().findOTForPage(obj, function (err, count, pageCount, datas) {
            if (err) {
            }
            page.pageCount = pageCount;
            var dates = [];
            for (var i = 0; i < datas.length; i++) {
                dates.push((datas[i].date).toFormat('YYYY-MM-DD HH24:MI:SS'));
            }
            res.render('system/box_log', {
                datas: datas,
                dates: dates,
                page: page
            });
        })
    }

};

